package com.fingard.dsp.bank.sepro;

import com.alibaba.fastjson.JSONObject;
import com.fingard.FGBiz;
import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.specialDeal.SimulateHelper;
import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.authforrec.ReqAuthForRec;
import com.fingard.dsp.bank.reqrespobj.authforrec.ReqQryAuthForRec;
import com.fingard.dsp.bank.reqrespobj.balance.Req7506BalQry;
import com.fingard.dsp.bank.reqrespobj.balancecheck.ReqBalCheckQry;
import com.fingard.dsp.bank.reqrespobj.balancecheckconfirm.ReqBalCheckConfirmQry;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.deposit.Req7507DepQry;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.*;
import com.fingard.dsp.bank.reqrespobj.enumeration.ENDirectRight;
import com.fingard.dsp.bank.reqrespobj.single.ReqQrySingle;
import com.fingard.dsp.bank.reqrespobj.single.ReqSingle;
import com.fingard.dsp.bank.reqrespobj.transaction.Req7515TodayTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.Req7516HisTrans;
import com.fingard.dsp.bankset.MappingCode;
import com.fingard.dsp.tcpserver.RequestNIO;
import com.fingard.generalobj.ExecResponse;
import com.fingard.io.FileHelper;
import com.fingard.text.StringHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

public class Simulate {
    public static Object mutexSimulate;

    public RequestNIO p_bizO = null;

    public Simulate(RequestNIO bizO) {
        p_bizO = bizO;
        mutexSimulate = new Object();
    }

    public ExecResponse getSimulateStr(XmlTextReader xmlReader, ReqRespHeader tmpHeader) throws Exception {
        ExecResponse resp = new ExecResponse();
        resp.isSucceed = false;

        String tmpRespBody = "";

        if ("Contract".equalsIgnoreCase(tmpHeader.transType) || "QryContract".equalsIgnoreCase(tmpHeader.transType)) {
            // 签约挡板
            String contractSimulateFile = FGBiz.DSPHOME + File.separator + "dsp-config/Simulate" + File.separator + "Contract_Simulate.xml";
            p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 签约规则解析文件路径:" + contractSimulateFile + "\r\n\r\n");
            File tmpFile = new File(contractSimulateFile);
            if (tmpFile.exists()) {
                String fileTxt = FileHelper.readFileText(contractSimulateFile, "utf-8");
                XmlTextReader tmpXmlReader = new XmlTextReader(fileTxt);
                while (tmpXmlReader.read("/config")) {
                    String useSleepContract = tmpXmlReader.readedXElement.getSingleTextNotNull("useSleepContract");
                    if ("true".equalsIgnoreCase(useSleepContract)) {
                        String contractSleepTime = tmpXmlReader.readedXElement.getSingleTextNotNull("contractSleepTime");
                        if (StringHelper.isNullOrEmpty(contractSleepTime)) {
                            contractSleepTime = "0";
                        }
                        long sleepTime = Long.parseLong(Format.DecimalIntFormat.format(Double.parseDouble(contractSleepTime)*1000));
                        synchronized (mutexSimulate) {
                            Thread.sleep(sleepTime);
                        }
                    }

                    boolean isMatched = true;

                    ArrayList<XElement> groupList = tmpXmlReader.readedXElement.getChildList("group");
                    if(groupList!=null && groupList.size() > 0) {
                        for(final XElement gXe : groupList) {
                            isMatched = true;
                            XElement xeTimer = gXe.getSingleChild("contractrule");
                            p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前匹配规则:" + xeTimer.getAttrValue("readme") + "\r\n\r\n");
                            if(xeTimer!=null){
                                ArrayList<XElement> childList = xeTimer.getAllChildList();
                                if (childList != null) {
                                    p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 开始进行规则匹配...\r\n");
                                    for(final XElement childElement : childList) {
                                        String childName = childElement.name;
                                        String childText = childElement.innerText;
                                        p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前规则匹配字段名("+childName+")\r\n");

                                        if ("BankCode".equalsIgnoreCase(childName) || "TransType".equalsIgnoreCase(childName) || "CommandCode".equalsIgnoreCase(childName)) {
                                            String oriChildName = xmlReader.getFirstTextNotNull("/ATSYH/TransReq/" + childName);
                                            p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前规则匹配字段名对应值:("+childText+")\r\n");
                                            p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 来源系统匹配字段名对应值:("+oriChildName+")\r\n");
                                            if (!childText.equalsIgnoreCase(oriChildName)) {
                                                isMatched = false;
                                                p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前规则匹配字段名匹配不一致,断开当前匹配规则,开始进入下一匹配规则...\r\n\r\n");
                                                break;
                                            }
                                        } else {
                                            if (childText.contains("%")) {
                                                int countChar = StringHelper.countChar(childText, '%');
                                                if (countChar == 2) {
                                                    // 两个%
                                                    int startIndex = childText.indexOf("%");
                                                    int endIndex = childText.lastIndexOf("%");
                                                    String matchStr = childText.substring(startIndex+1,endIndex);
                                                    p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前规则匹配字段名模糊匹配值:("+matchStr+")\r\n");
                                                    p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 来源系统匹配字段名实际值:("+xmlReader.getFirstTextNotNull("/ATSYH/TransReq/TransParam/DetailRecord/" + childName) + "\r\n");
                                                    if (!xmlReader.getFirstTextNotNull("/ATSYH/TransReq/TransParam/DetailRecord/" + childName).contains(matchStr)) {
                                                        isMatched = false;
                                                        p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前规则匹配字段名模糊匹配不一致,断开当前匹配规则,开始进入下一匹配规则...\r\n");
                                                        break;
                                                    }
                                                } else if (countChar == 1) {
                                                    // 一个%
                                                    String matchStr = childText.substring(childText.indexOf("%")+1);
                                                    p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前规则匹配字段名模糊匹配值:("+matchStr+")\r\n");
                                                    p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 来源系统匹配字段名实际值:("+xmlReader.getFirstTextNotNull("/ATSYH/TransReq/TransParam/DetailRecord/" + childName) + "\r\n");
                                                    if (!xmlReader.getFirstTextNotNull("/ATSYH/TransReq/TransParam/DetailRecord/" + childName).endsWith(matchStr)) {
                                                        isMatched = false;
                                                        p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前规则匹配字段名模糊匹配不一致,断开当前匹配规则,开始进入下一匹配规则...\r\n");
                                                        break;
                                                    }
                                                }
                                            } else {
                                                p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前规则匹配字段名对应值:("+childText+")\r\n");
                                                p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 来源系统匹配字段名对应值:("+xmlReader.getFirstTextNotNull("/ATSYH/TransReq/TransParam/DetailRecord/" + childName)+")\r\n");
                                                if (!childText.equalsIgnoreCase(xmlReader.getFirstTextNotNull("/ATSYH/TransReq/TransParam/DetailRecord/" + childName))) {
                                                    isMatched = false;
                                                    p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前规则匹配字段名匹配不一致,断开当前匹配规则,开始进入下一匹配规则...\r\n");
                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    if (isMatched) {
                                        // 匹配成功
                                        p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 当前规则匹配成功,开始返回...\r\n\r\n");
                                        XElement xerResp = gXe.getSingleChild("contractresp");
                                        if(xerResp!=null){
                                            XmlTextWriter xmlWriter = new XmlTextWriter();
                                            xmlWriter.writeStartElement("ATSYH");
                                            xmlWriter.writeStartElement("TransResp");
                                            xmlWriter.writeElementString("BankCode", xmlReader.getFirstTextNotNull("/ATSYH/TransReq/BankCode"));
                                            xmlWriter.writeElementString("TransType", xmlReader.getFirstTextNotNull("/ATSYH/TransReq/TransType"));
                                            xmlWriter.writeElementString("TransSeqID", xmlReader.getFirstTextNotNull("/ATSYH/TransReq/TransSeqID"));
                                            xmlWriter.writeStartElement("TransParam");
                                            xmlWriter.writeStartElement("DetailRecord");

                                            ArrayList<XElement> childsList = xerResp.getSingleChild("ATSYH").getSingleChild("TransResp").getSingleChild("TransParam").getSingleChild("DetailRecord").getAllChildList();
                                            if (childsList != null) {
                                                for (final XElement childsElement : childsList) {
                                                    String childName = childsElement.name;
                                                    String childText = childsElement.innerText;
                                                    if (childText.contains("{$")) {
                                                        String replaceStr = childText.replace("{$", "").replace("}", "");
                                                        childText = childText.replace("{$" + replaceStr + "}", xmlReader.getFirstTextNotNull("/ATSYH/TransReq/TransParam/DetailRecord/" + replaceStr));
                                                    }
                                                    xmlWriter.writeElementString(childName, childText);
                                                }
                                            }
                                            xmlWriter.writeEndDocument();
                                            tmpRespBody = xmlWriter.toXmlString();
                                            break;
                                        } else {
                                            tmpRespBody = "<ATSYH><TransResp><TransParam><RespCode>-1</RespCode><RespInfo>签约规则匹配成功,但是不存在响应ATS报文,请检查签约规则解析文件配置!</RespInfo></TransParam></TransResp></ATSYH>";
                                        }
                                    }
                                }
                            }
                        }

                        if (!isMatched) {
                            // 所有规则均匹配失败
                            p_bizO.sbLog.append(Format.DateTimeSSSFormat.format(p_bizO.recCompleteTime) + " 所有规则匹配均失败,开始返回统一错误信息...\r\n\r\n");
                            tmpRespBody = "<ATSYH><TransResp><TransParam><RespCode>-1</RespCode><RespInfo>签约状态未知!</RespInfo></TransParam></TransResp></ATSYH>";
                        }
                    } else {
                        tmpRespBody = "<ATSYH><TransResp><TransParam><RespCode>-1</RespCode><RespInfo>未设置签约规则,请检查签约规则解析文件("+contractSimulateFile+")配置!</RespInfo></TransParam></TransResp></ATSYH>";
                    }
                }
            } else {
                tmpRespBody = "<ATSYH><TransResp><TransParam><RespCode>-1</RespCode><RespInfo>签约规则解析文件("+contractSimulateFile+")不存在!</RespInfo></TransParam></TransResp></ATSYH>";
            }
        } else {
            String tmpRetFile = FGBiz.DSPHOME + File.separator + "dsp-config/Simulate" + File.separator + tmpHeader.bankCode + "_" + tmpHeader.transType + "resp.xml";
            File tmpFile = new File(tmpRetFile);
            if (!tmpFile.exists()) {
                tmpRetFile = FGBiz.DSPHOME + File.separator + "dsp-config/Simulate" + File.separator + "DSP_" + tmpHeader.transType + "resp.xml";
                tmpFile = new File(tmpRetFile);
            /*if (!tmpFile.exists()) {
                tmpRetFile = FGBiz.DSPHOME + File.separator + "Simulate" + File.separator + "DSP_" + tmpHeader.transType + "resp.xml";
                tmpFile = new File(tmpRetFile);
            }*/
            }
            if (tmpFile.exists()) {
                tmpRespBody = FileHelper.readToString(tmpFile, "utf-8");
                tmpRespBody = tmpRespBody.replace("{$BankCode}", tmpHeader.bankCode);
                tmpRespBody = tmpRespBody.replace("{$TransSeqID}", tmpHeader.transSeqID);

                if (StringHelper.hasAnyChar(tmpHeader.reqSeqID)) {
                    tmpRespBody = tmpRespBody.replace("{$ReqSeqID}", tmpHeader.reqSeqID);
                }
                if (tmpHeader.transType.equals("B006")) {
                    ReqB006BillStateQry tmpB006 = new ReqB006BillStateQry(xmlReader, tmpHeader);
                    tmpB006.readRecord();
                    tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "A06");
                    tmpRespBody = tmpRespBody.replace("{$TransState}", "A06");
                    tmpRespBody = tmpRespBody.replace("{$BillState}", "");
                    tmpRespBody = tmpRespBody.replace("{$BillNo}", tmpB006.detail.billNo);
                }
                String transState = "";
                String payCode = "";
                String payInfo = "";
                String newAuthCode = "";
                String payInfoCode = "";
                String signState = "";
                String retCode = "";
                String retMsg = "";
                String unifiedCode = "";
                String signConfirmType = "";
                String signUrl = "";
                String token = "";
                String respInfo = "";
                String transAmt = "";
                String postScript = "";
                String recName = "";
                String cardType = "";
                String certType = "";
                String certNum = "";
                String cellPhone = "";
                String deadLine = "";
                String singleLimit = "";
                String periodLimit = "";
                String countLimit = "";
                String iSeqno = "";
                String recAct = "";
                String authCode = "";
                String directPayWay = "";
                String packetType = "";
                String localFilePath = FGBiz.DSPHOME + File.separator + tmpHeader.bankCode;
                String fileName = "";
                if (tmpHeader.transType.equals("7506")) {
                    Req7506BalQry tmpReq7506 = new Req7506BalQry(xmlReader, tmpHeader);
                    tmpReq7506.readRecord();
                    tmpRespBody = tmpRespBody.replace("{$ActArea}", tmpReq7506.readedDetail.actArea);
                    tmpRespBody = tmpRespBody.replace("{$ActCur}", tmpReq7506.readedDetail.actCur);
                    Random random = new Random();
                    tmpRespBody = tmpRespBody.replace("{$CurrBal}", String.format("%.2f", 10000 * random.nextDouble()));
                    tmpRespBody = tmpRespBody.replace("{$ActNum}", tmpReq7506.readedDetail.actNum);
                    if (tmpReq7506.readedDetail.directRight.contains(ENDirectRight.CASHPOOLS.getValue())) {
                        tmpRespBody = tmpRespBody.replace("{$CashPoolBal}", String.format("%.2f", 10000 * random.nextDouble()));
                        tmpRespBody = tmpRespBody.replace("{$CashPoolAvailBal}", String.format("%.2f", 10000 * random.nextDouble()));
                    } else {
                        tmpRespBody = tmpRespBody.replace("{$CashPoolBal}", String.format("0"));
                        tmpRespBody = tmpRespBody.replace("{$CashPoolAvailBal}", String.format("0"));
                    }
                }
                if (tmpHeader.transType.equals("7507")) {
                    Req7507DepQry tmpReq7507 = new Req7507DepQry(xmlReader, tmpHeader);
                    tmpRespBody = tmpRespBody.replace("{$ActArea}", tmpReq7507.actArea);
                    tmpRespBody = tmpRespBody.replace("{$ActNum}", tmpReq7507.actNum);
                }
//                if (tmpHeader.transType.equals("B001")) {
//
//                    tmpRespBody = retAts.getRetAtsString();
//                }

                if (tmpHeader.transType.equals("B004")) {
                    ReqB004BillFrontQry tmpB004 = new ReqB004BillFrontQry(xmlReader, tmpHeader);
                    tmpB004.readRecord();
                    tmpRespBody = tmpRespBody.replace("{$BillNo}", tmpB004.detail.billNo);
                }

                if (tmpHeader.transType.equals("B005")) {
                    ReqB005BillBackQry tmpB004 = new ReqB005BillBackQry(xmlReader, tmpHeader);
                    tmpB004.readRecord();
                    tmpRespBody = tmpRespBody.replace("{$BillNo}", tmpB004.detail.billNo);
                }
                if (tmpHeader.transType.equals("B007")) {
                    ReqB007BillKzsrQry tmpB007 = new ReqB007BillKzsrQry(xmlReader, tmpHeader);
                    tmpB007.readRecord();
                    tmpRespBody = tmpRespBody.replace("{$BillNo}", tmpB007.detail.billNo);
                    tmpRespBody = tmpRespBody.replace("{$ReceName}", "中信出票测试");
                    tmpRespBody = tmpRespBody.replace("{$ReceAct}", "8110701013601222594");
                    tmpRespBody = tmpRespBody.replace("{$ReceBnkCode}", "302100011995");
                }
                if (tmpHeader.transType.equals("7508")) {
                    ReqBalCheckQry tmpReq7508 = new ReqBalCheckQry(xmlReader, tmpHeader);
                    tmpRespBody = tmpRespBody.replace("{$ActNum}", tmpReq7508.actNum);
                    tmpRespBody = tmpRespBody.replace("{$NoteDate}", tmpReq7508.yearMonth);
                    tmpRespBody = tmpRespBody.replace("{$toDate}", tmpReq7508.yearMonth);
                    Random random = new Random();
                    tmpRespBody = tmpRespBody.replace("{$ActBal}", String.format("%.2f", 10000 * random.nextDouble()));
                }
                if (tmpHeader.transType.equals("7509")) {
                    ReqBalCheckConfirmQry tmpReq7509 = new ReqBalCheckConfirmQry(xmlReader, tmpHeader);
                    tmpReq7509.readRecord();
                    tmpRespBody = tmpRespBody.replace("{$ActNum}", tmpReq7509.readedDetail.actNum);
                    tmpRespBody = tmpRespBody.replace("{$DZDNo}", tmpReq7509.readedDetail.statementNumber);
                    tmpRespBody = tmpRespBody.replace("{$DZFlag}", tmpReq7509.readedDetail.dzFlag);
                    tmpRespBody = tmpRespBody.replace("{$ActCur}", tmpReq7509.readedDetail.actCur);
                }
                if (tmpHeader.transType.equals("7515")) {
                    Req7515TodayTrans tmpReq7515 = new Req7515TodayTrans(xmlReader, tmpHeader);
                    tmpRespBody = tmpRespBody.replace("{$ActNum}", tmpReq7515.actNum);
                    tmpRespBody = tmpRespBody.replace("{$ActArea}", tmpReq7515.actArea);
                    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                    tmpRespBody = tmpRespBody.replace("{$Date}", df.format(new Date()));
                }

                if (tmpHeader.transType.equals("7516")) {
                    Req7516HisTrans p_req7516 = new Req7516HisTrans(xmlReader, tmpHeader);
                    tmpRespBody = tmpRespBody.replace("{$ActNum}", p_req7516.actNum);
                    tmpRespBody = tmpRespBody.replace("{$ActArea}", p_req7516.actArea);
                    Calendar tmpCalendarFrom = Calendar.getInstance();
                    tmpCalendarFrom.setTime(p_req7516.getDateFrom());
                    tmpRespBody = tmpRespBody.replace("{$Date}", Format.Date10Format.format(tmpCalendarFrom.getTime()));
                }
                if (tmpHeader.transType.equals("1908") || tmpHeader.transType.equals("1944") || tmpHeader.transType.equals("6908") || tmpHeader.transType.equals("6944") || tmpHeader.transType.equals("9108") || tmpHeader.transType.equals("9144") || tmpHeader.transType.equals("9110") || tmpHeader.transType.equals("9146") || tmpHeader.transType.equals("1988") || tmpHeader.transType.equals("1998") || tmpHeader.transType.equals("7527") || tmpHeader.transType.equals("9188") || tmpHeader.transType.equals("9198") || tmpHeader.transType.equals("ENDIIMPT") || tmpHeader.transType.equals("QENDIIMPT")) {
                    MappingCode mappingCode = new MappingCode();
                    Map<String, Object> map = mappingCode.readTransStateByMappingCode(tmpHeader);
                    Map mapQuery = new HashMap();
                    if (tmpHeader.transType.equals("1908")) {
                        ReqSingle p_req = new ReqSingle(xmlReader, tmpHeader);
                        for (Map.Entry<String, Object> entry : map.entrySet()) {
                            mappingCode = (MappingCode) entry.getValue();
                            directPayWay = "1";
                            packetType = "1";
                            String actNum = p_req.singleDetail.payAct;
                            actNum = actNum.substring(actNum.length() - 1, actNum.length());
                            if (actNum.equals("1") || actNum.equals("5")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("未知错误（系统忙）")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            } else if (actNum.equals("3") || actNum.equals("2")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("交易失败")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            } else if (actNum.equals("4") || actNum.equals("6") || actNum.equals("7") || actNum.equals("8") || actNum.equals("9") || actNum.equals("0")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("余额")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    JSONObject detail = new JSONObject();
                                    detail.put("payAmount", p_req.singleDetail.payAmount);
                                    detail.put("payAct", p_req.singleDetail.payAct);
                                    mapQuery.put(p_req.reqHeader.reqSeqID, detail);
                                    // 打开一个随机访问文件流，按读写方式
                                    fileName = p_req.reqHeader.commandCode + ".txt";
                                    localFilePath += fileName;
                                    mappingCode.writeFile(localFilePath, mapQuery);
                                    break;
                                }
                            }
                        }
                    } else if (tmpHeader.transType.equals("1944")) {
                        ReqQrySingle p_req = new ReqQrySingle(xmlReader, tmpHeader);
                        for (Map.Entry<String, Object> entry : map.entrySet()) {
                            mappingCode = (MappingCode) entry.getValue();
                            directPayWay = "1";
                            packetType = "2";
                            String actNum = p_req.payAct;
                            actNum = actNum.substring(actNum.length() - 1, actNum.length());
                            if (actNum.equals("1") || actNum.equals("5")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("可用余额不足")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    transAmt = "";
                                    break;
                                }
                            } else if (actNum.equals("3") || actNum.equals("2")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("账号不存在")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    transAmt = "";
                                    break;
                                }
                            } else if (actNum.equals("4") || actNum.equals("6") || actNum.equals("7") || actNum.equals("8") || actNum.equals("9") || actNum.equals("0")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("交易成功")) {
                                    fileName = p_req.reqHeader.commandCode + ".txt";
                                    localFilePath += fileName;
                                    Map<String, Object> query = mappingCode.readQyerys(localFilePath);
                                    for (String a : query.keySet()) {
                                        if (a.equals(p_req.askNumber)) {
                                            JSONObject object = (JSONObject) query.get(a);
                                            transAmt = object.getString("payAmount");
                                        }
                                    }
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            }
                        }
                    } else if (tmpHeader.transType.equals("9108")) {
                        ReqSingle p_req = new ReqSingle(xmlReader, tmpHeader);
                        for (Map.Entry<String, Object> entry : map.entrySet()) {
                            mappingCode = (MappingCode) entry.getValue();
                            directPayWay = "5";
                            packetType = "1";
                            String actNum = p_req.singleDetail.payAct;
                            actNum = actNum.substring(actNum.length() - 1, actNum.length());
                            if (actNum.equals("1") || actNum.equals("5")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("卡号不合法或不存在")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            } else if (actNum.equals("3") || actNum.equals("2")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("提交失败")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            } else if (actNum.equals("4") || actNum.equals("6") || actNum.equals("7") || actNum.equals("8") || actNum.equals("9") || actNum.equals("0")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("提交成功")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    JSONObject detail = new JSONObject();
                                    detail.put("payAmount", p_req.singleDetail.payAmount);
                                    detail.put("payAct", p_req.singleDetail.payAct);
                                    mapQuery.put(p_req.reqHeader.reqSeqID, detail);
                                    // 打开一个随机访问文件流，按读写方式
                                    fileName = p_req.reqHeader.commandCode + ".txt";
                                    localFilePath += fileName;
                                    mappingCode.writeFile(localFilePath, mapQuery);
                                    break;
                                }
                            }
                        }
                    } else if (tmpHeader.transType.equals("9144")) {
                        ReqQrySingle p_req = new ReqQrySingle(xmlReader, tmpHeader);
                        for (Map.Entry<String, Object> entry : map.entrySet()) {
                            mappingCode = (MappingCode) entry.getValue();
                            directPayWay = "5";
                            packetType = "2";
                            String actNum = p_req.payAct;
                            actNum = actNum.substring(actNum.length() - 1, actNum.length());
                            if (actNum.equals("1") || actNum.equals("5")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("帐户金额不足")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    transAmt = "";
                                    break;
                                }
                            } else if (actNum.equals("3") || actNum.equals("2")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("记录不存在")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    transAmt = "";
                                    break;
                                }
                            } else if (actNum.equals("4") || actNum.equals("6") || actNum.equals("7") || actNum.equals("8") || actNum.equals("9") || actNum.equals("0")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("处理成功")) {
                                    fileName = p_req.reqHeader.commandCode + ".txt";
                                    localFilePath += fileName;
                                    Map<String, Object> query = mappingCode.readQyerys(localFilePath);
                                    for (String a : query.keySet()) {
                                        if (a.equals(p_req.askNumber)) {
                                            JSONObject object = (JSONObject) query.get(a);
                                            transAmt = object.getString("payAmount");
                                        }
                                    }
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            }
                        }
                    } else if (tmpHeader.transType.equals("1988")) {
                        ReqBatPayRec p_req = new ReqBatPayRec(xmlReader, tmpHeader);
                        while (p_req.readRecord()) {
                            for (Map.Entry<String, Object> entry : map.entrySet()) {
                                mappingCode = (MappingCode) entry.getValue();
                                directPayWay = "2";
                                packetType = "1";
                                String actNum = p_req.ownAct;
                                actNum = actNum.substring(actNum.length() - 1, actNum.length());
                                if (actNum.equals("1") || actNum.equals("5")) {
                                    if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("提交失败")) {
                                        transState = mappingCode.payCode;
                                        payInfoCode = mappingCode.payInfoCode;
                                        respInfo = mappingCode.payInfo;
                                        break;
                                    }
                                } else if (actNum.equals("3") || actNum.equals("2")) {
                                    if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("账户不允许透支")) {
                                        transState = mappingCode.payCode;
                                        payInfoCode = mappingCode.payInfoCode;
                                        respInfo = mappingCode.payInfo;
                                        break;
                                    }
                                } else if (actNum.equals("4") || actNum.equals("6") || actNum.equals("7") || actNum.equals("8") || actNum.equals("9") || actNum.equals("0")) {
                                    if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("提交成功")) {
                                        transState = mappingCode.payCode;
                                        payInfoCode = mappingCode.payInfoCode;
                                        respInfo = mappingCode.payInfo;
                                        JSONObject detail = new JSONObject();
                                        detail.put("postScript", p_req.readedDetail.askNumber);
                                        detail.put("payAmount", p_req.readedDetail.payAmount);
                                        detail.put("payAct", p_req.readedDetail.payAct);
                                        detail.put("payName", p_req.readedDetail.payName);
                                        mapQuery.put(p_req.reqHeader.reqSeqID, detail);
                                        // 打开一个随机访问文件流，按读写方式
                                        fileName = p_req.reqHeader.commandCode + ".txt";
                                        localFilePath += fileName;
                                        mappingCode.writeFile(localFilePath, mapQuery);
                                        break;
                                    }
                                }
                            }
                        }
                    } else if (tmpHeader.transType.equals("1998")) {
                        ReqQryBatPayRec p_req = new ReqQryBatPayRec(xmlReader, tmpHeader);
                        for (Map.Entry<String, Object> entry : map.entrySet()) {
                            mappingCode = (MappingCode) entry.getValue();
                            directPayWay = "4";
                            packetType = "1";
                            String actNum = p_req.ownAct;
                            actNum = actNum.substring(actNum.length() - 1, actNum.length());
                            if (actNum.equals("1") || actNum.equals("5")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("发现非法账号")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            } else if (actNum.equals("3") || actNum.equals("2")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("交易失败")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            } else if (actNum.equals("4") || actNum.equals("6") || actNum.equals("7") || actNum.equals("8") || actNum.equals("9") || actNum.equals("0")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("成功")) {
                                    fileName = p_req.reqHeader.commandCode + ".txt";
                                    localFilePath += fileName;
                                    Map<String, Object> query = mappingCode.readQyerys(localFilePath);
                                    for (String a : query.keySet()) {
                                        if (a.equals(p_req.reqBatchNO)) {
                                            JSONObject object = (JSONObject) query.get(a);
                                            transAmt = object.getString("payAmount");
                                            postScript = object.getString("postScript");
                                            recName = object.getString("payName");
                                            recAct = object.getString("payAct");
                                            break;
                                        }
                                    }
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            }
                        }
                    } else if (tmpHeader.transType.equals("9188")) {
                        ReqBatPayRec p_req = new ReqBatPayRec(xmlReader, tmpHeader);
                        while (p_req.readRecord()) {
                            for (Map.Entry<String, Object> entry : map.entrySet()) {
                                mappingCode = (MappingCode) entry.getValue();
                                directPayWay = "4";
                                packetType = "1";
                                String actNum = p_req.ownAct;
                                actNum = actNum.substring(actNum.length() - 1, actNum.length());
                                if (actNum.equals("1") || actNum.equals("5")) {
                                    if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("发现非法账号")) {
                                        transState = mappingCode.payCode;
                                        payInfoCode = mappingCode.payInfoCode;
                                        respInfo = mappingCode.payInfo;
                                        break;
                                    }
                                } else if (actNum.equals("3") || actNum.equals("2")) {
                                    if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("交易失败")) {
                                        transState = mappingCode.payCode;
                                        payInfoCode = mappingCode.payInfoCode;
                                        respInfo = mappingCode.payInfo;
                                        break;
                                    }
                                } else if (actNum.equals("4") || actNum.equals("6") || actNum.equals("7") || actNum.equals("8") || actNum.equals("9") || actNum.equals("0")) {
                                    if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("成功")) {
                                        transState = mappingCode.payCode;
                                        payInfoCode = mappingCode.payInfoCode;
                                        respInfo = mappingCode.payInfo;
                                        JSONObject detail = new JSONObject();
                                        detail.put("postScript", p_req.readedDetail.askNumber);
                                        detail.put("payAmount", p_req.readedDetail.payAmount);
                                        detail.put("payAct", p_req.readedDetail.payAct);
                                        detail.put("payName", p_req.readedDetail.payName);
                                        mapQuery.put(p_req.reqHeader.reqSeqID, detail);
                                        // 打开一个随机访问文件流，按读写方式
                                        fileName = p_req.reqHeader.commandCode + ".txt";
                                        localFilePath += fileName;
                                        mappingCode.writeFile(localFilePath, mapQuery);
                                        break;
                                    }
                                }
                            }
                        }
                    } else if (tmpHeader.transType.equals("9198")) {
                        ReqQryBatPayRec p_req = new ReqQryBatPayRec(xmlReader, tmpHeader);
                        for (Map.Entry<String, Object> entry : map.entrySet()) {
                            mappingCode = (MappingCode) entry.getValue();
                            directPayWay = "4";
                            packetType = "1";
                            String actNum = p_req.ownAct;
                            actNum = actNum.substring(actNum.length() - 1, actNum.length());
                            if (actNum.equals("1") || actNum.equals("5")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("发现非法账号")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            } else if (actNum.equals("3") || actNum.equals("2")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("交易失败")) {
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            } else if (actNum.equals("4") || actNum.equals("6") || actNum.equals("7") || actNum.equals("8") || actNum.equals("9") || actNum.equals("0")) {
                                if (mappingCode.directPayWay.equals(directPayWay) && mappingCode.packetType.equals(packetType) && mappingCode.payInfo.contains("成功")) {
                                    fileName = p_req.reqHeader.commandCode + ".txt";
                                    localFilePath += fileName;
                                    Map<String, Object> query = mappingCode.readQyerys(localFilePath);
                                    for (String a : query.keySet()) {
                                        if (a.equals(p_req.reqBatchNO)) {
                                            JSONObject object = (JSONObject) query.get(a);
                                            transAmt = object.getString("payAmount");
                                            postScript = object.getString("postScript");
                                            recName = object.getString("payName");
                                            recAct = object.getString("payAct");
                                            break;
                                        }
                                    }
                                    transState = mappingCode.payCode;
                                    payInfoCode = mappingCode.payInfoCode;
                                    respInfo = mappingCode.payInfo;
                                    break;
                                }
                            }
                        }
                    }else if (tmpHeader.transType.equals("ENDIIMPT")) {
                        ReqAuthForRec p_req = new ReqAuthForRec(xmlReader, tmpHeader);
                        while (p_req.readRecord()) {
                            String actNum = p_req.ownAct;
                            actNum = actNum.substring(actNum.length() - 1, actNum.length());
                            if (actNum.equals("1") || actNum.equals("5")) {
                                retCode = "1";
                                retMsg = "发现非法账号";
                                respInfo = "发现非法账号";
                            } else if (actNum.equals("3") || actNum.equals("2")) {
                                retCode = "1";
                                retMsg = "交易失败";
                                respInfo = "交易失败";
                            } else if (actNum.equals("4") || actNum.equals("6") || actNum.equals("7") || actNum.equals("8") || actNum.equals("9") || actNum.equals("0")) {
                                retCode = "2";
                                transState = "2";
                                respInfo = "交易成功";
                                retMsg = "交易成功";
                                JSONObject detail = new JSONObject();
                                detail.put("postScript", p_req.reqSeqID);
                                detail.put("authCode", p_req.readedDetail.authCode);
                                detail.put("oppActName", p_req.readedDetail.oppActName);
                                detail.put("oppAct", p_req.readedDetail.oppAct);
                                mapQuery.put(p_req.reqHeader.reqSeqID, detail);
                                // 打开一个随机访问文件流，按读写方式
                                fileName = p_req.reqHeader.commandCode + ".txt";
                                localFilePath += fileName;
                                mappingCode.writeFile(localFilePath, mapQuery);
                            }
                        }
                    } else if (tmpHeader.transType.equals("QENDIIMPT")) {
                        ReqQryAuthForRec p_req = new ReqQryAuthForRec(xmlReader, tmpHeader);
                        String actNum = p_req.reqSeqID;
                        actNum = actNum.substring(actNum.length() - 1, actNum.length());
                        if (actNum.equals("1") || actNum.equals("5")) {
                            retCode = "1";
                            retMsg = "发现非法账号";
                            respInfo = "发现非法账号";
                        } else if (actNum.equals("3") || actNum.equals("2")) {
                            retCode = "1";
                            retMsg = "交易失败";
                            respInfo = "交易失败";
                        } else if (actNum.equals("4") || actNum.equals("6") || actNum.equals("7") || actNum.equals("8") || actNum.equals("9") || actNum.equals("0")) {
                            fileName = p_req.reqHeader.commandCode + ".txt";
                            localFilePath += fileName;
                            Map<String, Object> query = mappingCode.readQyerys(localFilePath);
                            for (String a : query.keySet()) {
                                if (a.equals(p_req.reqSeqID)) {
                                    JSONObject object = (JSONObject) query.get(a);
                                    postScript = object.getString("postScript");
                                    recAct = object.getString("oppAct");
                                    authCode = object.getString("authCode");
                                    recName = object.getString("oppActName");
                                    break;
                                }
                            }
                            payInfo = "签约成功";
                            newAuthCode = "1268654708653";
                            payCode = "000000";
                            transState = "2";
                            respInfo = "";
                        }
                    }
                    if (tmpHeader.bankCode.equals("ICBC02")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "0+9");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "0+7");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "0+7");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "0+7");
                        } else if (tmpHeader.transType.equals("1988")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "0");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "0");
                        } else if (tmpHeader.transType.equals("1998")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "0+7");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "0+7");
                        }
                    } else if (tmpHeader.bankCode.equals("BOC01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "B001");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "B001");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "B001");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "B001");
                        } else if (tmpHeader.transType.equals("1988")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "B001");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "B001");
                        } else if (tmpHeader.transType.equals("1998")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "B001");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "B001");
                        }
                    } else if (tmpHeader.bankCode.equals("CCB04")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$TransAmt}", transAmt);
                        } else if (tmpHeader.transType.equals("9108")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("9144")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$TransAmt}", transAmt);
                        } else if (tmpHeader.transType.equals("1988")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("1998")) {
                            tmpRespBody = tmpRespBody.replace("{$PostScript}", postScript);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$Result}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$PayAmount}", transAmt);
                            tmpRespBody = tmpRespBody.replace("{$RecName}", recName);
                            tmpRespBody = tmpRespBody.replace("{$RecAct}", recAct);
                        } else if (tmpHeader.transType.equals("9188")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("9198")) {
                            tmpRespBody = tmpRespBody.replace("{$PostScript}", postScript);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$Result}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$PayAmount}", transAmt);
                            tmpRespBody = tmpRespBody.replace("{$PayName}", recName);
                            tmpRespBody = tmpRespBody.replace("{$PayAct}", recAct);
                        }
                    } else if (tmpHeader.bankCode.equals("CCB01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "M0001");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "M0001");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "M0001+1");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "M0001+1");
                        }
                    } else if (tmpHeader.bankCode.equals("ABC01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "4");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "4");
                        }
                    } else if (tmpHeader.bankCode.equals("ABC02")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$TransAmt}", transAmt);
                        } else if (tmpHeader.transType.equals("9108")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("9144")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$TransAmt}", transAmt);
                        } else if (tmpHeader.transType.equals("1988")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("1998")) {
                            tmpRespBody = tmpRespBody.replace("{$PostScript}", postScript);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$Result}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$PayAmount}", transAmt);
                            tmpRespBody = tmpRespBody.replace("{$RecName}", recName);
                            tmpRespBody = tmpRespBody.replace("{$RecAct}", recAct);
                        } else if (tmpHeader.transType.equals("9188")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("9198")) {
                            tmpRespBody = tmpRespBody.replace("{$PostScript}", postScript);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$Result}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$PayAmount}", transAmt);
                            tmpRespBody = tmpRespBody.replace("{$PayName}", recName);
                            tmpRespBody = tmpRespBody.replace("{$PayAct}", recAct);
                        }
                    } else if (tmpHeader.bankCode.equals("BOCOM13")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$TransAmt}", transAmt);
                        } else if (tmpHeader.transType.equals("9108")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("9144")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$TransAmt}", transAmt);
                        } else if (tmpHeader.transType.equals("1988")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("1998")) {
                            tmpRespBody = tmpRespBody.replace("{$PostScript}", postScript);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$Result}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$PayAmount}", transAmt);
                            tmpRespBody = tmpRespBody.replace("{$RecName}", recName);
                            tmpRespBody = tmpRespBody.replace("{$RecAct}", recAct);
                        } else if (tmpHeader.transType.equals("9188")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                        } else if (tmpHeader.transType.equals("9198")) {
                            tmpRespBody = tmpRespBody.replace("{$PostScript}", postScript);
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$Result}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", payInfoCode);
                            tmpRespBody = tmpRespBody.replace("{$PayAmount}", transAmt);
                            tmpRespBody = tmpRespBody.replace("{$PayName}", recName);
                            tmpRespBody = tmpRespBody.replace("{$PayAct}", recAct);
                        } else if (tmpHeader.transType.equals("ENDIIMPT")) {
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$RetCode}", retCode);
                            tmpRespBody = tmpRespBody.replace("{$RetMsg}", retMsg);
                        } else if (tmpHeader.transType.equals("QENDIIMPT")) {
                            tmpRespBody = tmpRespBody.replace("{$RespInfo}", respInfo);
                            tmpRespBody = tmpRespBody.replace("{$PayInfo}", payInfo);
                            tmpRespBody = tmpRespBody.replace("{$TransState}", transState);
                            tmpRespBody = tmpRespBody.replace("{$PayAcctNo}", recAct);
                            tmpRespBody = tmpRespBody.replace("{$PayAcctName}", recName);
                            tmpRespBody = tmpRespBody.replace("{$ISeqno}", authCode);
                            tmpRespBody = tmpRespBody.replace("{$PayCode}", payCode);
                            tmpRespBody = tmpRespBody.replace("{$PayInfo}", payInfo);
                            tmpRespBody = tmpRespBody.replace("{$NewAuthCode}", newAuthCode);
                        }
                    } else if (tmpHeader.bankCode.equals("CRBC01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "50");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "50");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "90");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "90");
                        } else if (tmpHeader.transType.equals("1988")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "90");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "90");
                        } else if (tmpHeader.transType.equals("1998")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "90");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "90");
                        }
                    } else if (tmpHeader.bankCode.equals("CMB01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "AUT");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "AUT");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "FIN+S");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "FIN+S");
                        }
                    } else if (tmpHeader.bankCode.equals("AllInPay02")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "AUT");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "AUT");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "FIN+S");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "FIN+S");
                        }
                    } else if (tmpHeader.bankCode.equals("GZELINK01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "AUT");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "AUT");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "FIN+S");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "FIN+S");
                        }
                    } else if (tmpHeader.bankCode.equals("PAB01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "000000");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "000000");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "000000+20");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "000000+20");
                        }
                    } else if (tmpHeader.bankCode.equals("PSBC01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "00+1");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "00+1");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "00+1");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "00+1");
                        }
                    } else if (tmpHeader.bankCode.equals("SPDB01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "0");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "0");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "4");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "4");
                        }
                    } else if (tmpHeader.bankCode.equals("BON02")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "0+1");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "0+1");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "0+4");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "0+4");
                        }
                    } else if (tmpHeader.bankCode.equals("BOCOM01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "0000");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "0000");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "0000+F");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "0000+F");
                        }
                    } else if (tmpHeader.bankCode.equals("CIB01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "0");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "0");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "PAYOUT");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "PAYOUT");
                        }
                    } else if (tmpHeader.bankCode.equals("CITIC01")) {
                        if (tmpHeader.transType.equals("1908")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "AAAAAAB");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "AAAAAAB");
                        } else if (tmpHeader.transType.equals("1944")) {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", "AAAAAAA");
                            tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", "AAAAAAA");
                        }
                    } else {
                        Random random = new Random();
                        int max = 5;
                        int min = 2;
                        if (FGBiz.dspCenter.dspSet.simulateWithDB) {
                            SimulateHelper tmp = new SimulateHelper();
                            if ("999.99".equals(xmlReader.getSimpleTextNotNull("PayAmount"))) {
                                tmp.getFail(tmpHeader.bankCode, tmpHeader.transType);
                                tmpRespBody = tmpRespBody.replace("{$TransState}", tmp.transState);
                                tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", tmp.payInfoCode);
                            } else {
                                tmp.getSuccess(tmpHeader.bankCode, tmpHeader.transType);
                                tmpRespBody = tmpRespBody.replace("{$TransState}", tmp.transState);
                                tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", tmp.payInfoCode);
                            }
                        } else {
                            tmpRespBody = tmpRespBody.replace("{$TransState}", String.valueOf(random.nextInt(max) % (max - min + 1) + min));
                        }
                    }
                }

                if (FGBiz.dspCenter.dspSet.simulateWithDB) {
                    String operateType = "";
                    String operateFlag = "";//0-操作前 1-操作 2-操作后
                    boolean needGetTransState = false;
                    String qryTransType = "ECDS";
                    if (tmpHeader.transType.startsWith("B0")) {
                        if (xmlReader.getSimpleText("BusiType") != null) {
                            operateType = xmlReader.getSimpleText("BusiType") + "-";
                        }
                        if (xmlReader.getSimpleText("QueryType") != null) {
                            operateType = operateType + xmlReader.getSimpleText("QueryType");
                        }
                        if (tmpHeader.transType.equals("B006")) {
                            operateFlag = "2";
                            needGetTransState = true;
                            qryTransType = "B006";
                        } else {
                            operateFlag = "1";
                        }
                    }
                    if (tmpHeader.transType.startsWith("B1")) {
                        operateType = tmpHeader.transType;
                        operateFlag = "1";
                        needGetTransState = true;
                    }

                    if (needGetTransState) {
                        SimulateHelper tmp = new SimulateHelper();
                        tmp.getSuccess(tmpHeader.bankCode, qryTransType);
                        tmpRespBody = tmpRespBody.replace("{$TransState}", tmp.transState);
                        tmpRespBody = tmpRespBody.replace("{$PayInfoCode}", tmp.payInfoCode);
                    }

                    if (tmpRespBody.contains("{$BillState}")) {
                        SimulateHelper tmp = new SimulateHelper();
                        tmp.getBillState(tmpHeader.bankCode, operateType, operateFlag);
                        tmpRespBody = tmpRespBody.replace("{$BillState}", tmp.billState);
                    }
                }

                if (tmpHeader.transType.startsWith("B3")) {
                    tmpRespBody = tmpRespBody.replace("{$ReqSeqID}", StringHelper.hasAnyChar(tmpHeader.reqSeqID)?tmpHeader.reqSeqID:tmpHeader.transSeqID);
                }
            }
        }

        resp.isSucceed = true;
        resp.setResult(tmpRespBody);
        return resp;
    }
}